package com.team.six.bluecatshop.service;

import com.team.six.bluecatshop.domain.ShoppingCart;
import com.team.six.bluecatshop.mapper.ShoppingCartMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ShoppingCartServiceImpl implements ShoppingCartService {
    @Autowired
    private ShoppingCartMapper shoppingCartMapper;


    @Override
    @Transactional
    public void add(ShoppingCart shoppingCart) {
        shoppingCartMapper.insert(shoppingCart);
    }

    @Override
    @Transactional
    public void remove(String id) {
        shoppingCartMapper.deleteByPrimaryKey(id);
    }

    @Override
    public ShoppingCart findById(String id) {
        ShoppingCart shoppingCart=shoppingCartMapper.selectByPrimaryKey(id);
        return shoppingCart;
    }

    @Override
    public List<ShoppingCart> findAll() {
        List<ShoppingCart> shoppingCartList = shoppingCartMapper.findAll();
        return shoppingCartList;
    }

    @Override
    public ShoppingCart findShoppingCartByProductId(String id) {
        return shoppingCartMapper.findByProductId(id);
    }


    @Override
    @Transactional
    public void updateByPrimaryKey(ShoppingCart shoppingCart) {
        shoppingCartMapper.updateByPrimaryKeySelective(shoppingCart);
    }

    @Override
    public List<ShoppingCart> findShoppingCartByCustomerId(String customerId) {
        List<ShoppingCart> shoppingCart = shoppingCartMapper.findByCustomerId(customerId);
        return shoppingCart;
    }

    @Override
    public void multiDel(List<String> ids) {
        shoppingCartMapper.multiDel(ids);
    }

    @Override
    public void removeByProductIdAndCustomerId(String productId, String customerId) {
        shoppingCartMapper.removeByProductIdAndCustomerId(productId,customerId);
    }

    @Override
    public int findShoppingCartByCustomerID(String customerId) {
        return shoppingCartMapper.findShoppingCartByCustomerID(customerId);
    }
}
